<!--
 * @Author: ChunLai
 * @Date: 2022-07-14 10:45:54
 * @LastEditTime: 2025-09-05 08:40:43
 * @Description: 
 * @FilePath: \02.bldinsure\src\components\agentSyncBtn.vue
-->
<template>
  <div @click="agentValid">
    <slot></slot>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { appShare } from "@/utils";
export default {
  name: "AgentSyncBtn",
  components: {},
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      shareInfo: "home/shareInfo",
      preInsConfig: "home/preInsConfig",
      abutmentType: "varietyInfo/abutmentType",
      shareUrl: "varietyInfo/shareUrl",
      isOnline: "varietyInfo/isOnline",
      h5InsuLink: "page/h5InsuLink",
      h5InsuShareType: "page/h5InsuShareType",
    }),
    getH5JumpLink() {
      let res = "";
      let h5link = this.shareUrl || "";
      if (this.h5InsuLink) {
        h5link = `${this.h5InsuLink}/${this.mainRiskCode}`;
      }
      if (h5link) {
        res = `${h5link}?workNum=${this.workNum}`;
      }
      return res;
    },
  },
  methods: {
    /**投保前校验 */
    agentValid() {
      //互联网直接下一步
      if (this.isOnline == "1") {
        this.onLineNext();
      } else {
        this.goNextRouter();
      }
    },
    // 非互联网下一步
    goNextRouter() {
      // H5对接
      if (this.abutmentType == "1") {
        this.getH5Url();
      } else {
        // API对接
        this.routerPath();
      }
    },
    routerPath() {
      // H5对接/有权限/特殊产品
      if (this.preInsConfig) {
        this.$router.push("/preinsure");
      } else {
        this.$router.push("/count");
      }
    },
    // H5对接--获取投保链接
    getH5Url() {
      if (this.getH5JumpLink) {
        // APP 内分享
        if (this.origin == "ms") {
          // 分享第三方链接
          this.shareAction();
        } else {
          console.log("getH5Url", this.getH5JumpLink);
          window.location.replace(`${this.getH5JumpLink}`);
        }
      } else {
        this.$msAlert(`未配置投保链接`);
      }
    },
    /**互联网险种下一步-- */
    onLineNext() {
      // console.log("onLineNext");
      if (this.abutmentType == "1") {
        // H5对接
        if (this.getH5JumpLink) {
          console.log("onLineNext", this.getH5JumpLink);
          window.location.replace(`${this.getH5JumpLink}`);
        } else {
          this.$msAlert(`未配置投保链接`);
        }
      } else {
        // API对接
        this.routerPath();
      }
    },
    /**分享 */
    shareAction() {
      let shareLinnk = `${window.location.href.split("#")[0]}&skind=insure`;
      if (
        this.abutmentType == "1" &&
        this.getH5JumpLink &&
        this.h5InsuShareType == "4"
      ) {
        shareLinnk = `${this.getH5JumpLink}`;
      }
      let shareData = {
        ...this.shareInfo,
        url: shareLinnk,
      };
      appShare(shareData);
    },
  },
};
</script>

<style></style>
